//package com.wuzuqing.android.eightdiagrams
//
//import android.annotation.SuppressLint
//import android.os.Bundle
//import android.view.View
//import android.widget.CheckBox
//import android.widget.EditText
//import android.widget.RadioButton
//import android.widget.RadioGroup
//import android.widget.TextView
//import android.widget.Toast
//import androidx.recyclerview.widget.GridLayoutManager
//import androidx.recyclerview.widget.LinearLayoutManager
//import androidx.recyclerview.widget.RecyclerView
//import com.loper7.date_time_picker.DateTimeConfig
//import com.loper7.date_time_picker.dialog.CardDatePickerDialog
//import com.wuzuqing.android.eightdiagrams.base.BaseAdapter
//import com.wuzuqing.android.eightdiagrams.dao.BaZhiHistory
//import com.wuzuqing.android.eightdiagrams.db.DbManager
//import com.wuzuqing.android.eightdiagrams.model.*
//import com.wuzuqing.android.eightdiagrams.term.ExactDate
//import com.wuzuqing.android.eightdiagrams.term.Solar
//import com.wuzuqing.android.eightdiagrams.utils.*
//import java.text.SimpleDateFormat
//import java.util.*
//
//class BaZiDetailActivity : BaseActivity() {
//    lateinit var mTvSolar: TextView
//    lateinit var mTvLunar: TextView
//    lateinit var mTvCity: TextView
//    lateinit var mTvNickame: TextView
//    lateinit var mTvGender: TextView
//    lateinit var mTvShengXiao: TextView
//    lateinit var mTvMingGong: TextView
//    lateinit var mTvWenChangWei: TextView
//    lateinit var mRg: RadioGroup
//    lateinit var vRcvResult: RecyclerView
//    var selectTime = 0L
//    var mSelectCity: City? = null
//    var mSelectProvince = ""
//    var mHistoryData: BaZhiHistory? = null
//    private var dayMin = 86400 * 1000
//
//    @SuppressLint("SimpleDateFormat")
//    override fun onCreate(savedInstanceState: Bundle?) {
//        super.onCreate(savedInstanceState)
//
//        setContentView(R.layout.activity_bazi_detail)
//        mTvSolar = findViewById(R.id.tv_solar)
//        mTvCity = findViewById(R.id.tv_city)
//        mTvLunar = findViewById(R.id.tv_lunar)
//        mTvNickame = findViewById(R.id.tv_nickname)
//        mTvGender = findViewById(R.id.tv_gender)
//        mTvShengXiao = findViewById(R.id.tv_shengxiao)
//        mTvMingGong = findViewById(R.id.tv_minggong)
//        vRcvResult = findViewById(R.id.rcv)
//        mTvWenChangWei = findViewById(R.id.tv_wenchangwei)
//        mRg = findViewById(R.id.ming_group)
//
//        initRcv()
//        initResultRcv()
//        initDaYunLiuRcv()
//        val ca = Calendar.getInstance()
//        intent?.getSerializableExtra("data")?.also {
//            mHistoryData = it as BaZhiHistory
//            mHistoryData?.let { history ->
//                ca.timeInMillis = history.createTime
//                if (history.sexType != 1) {
//                    findViewById<RadioButton>(R.id.sex_girl).isChecked = true
//                }
//                mTvNickame.text = history.nickName
//            }
//        } ?: also {
//            ca.set(2002, 5, 15, 0, 1, 0)
//        }
//
//        chooseTime(ca.timeInMillis)
//    }
//
//    private fun optTime(field: Int, value: Int) {
//        val instance = Calendar.getInstance()
//        instance.timeInMillis = selectTime
//        instance.add(field, value)
//        chooseTime(instance.timeInMillis)
//    }
//
//
//    private var info: BaZiInfo? = null
//    private var currentYear = 0
//    private var currentMonth = 0
//    private var currentDay = 0
//    private fun startCs() {
//
//        val my = LuozhuangSunTime()
//        val fixTime = my.calculateTime(selectTime, mSelectCity?.toString().orEmpty())
//        LogUtils.d("calculateTime:fixTime:$${fixTime},selectTime:$selectTime")
//
//        val calendar = Calendar.getInstance()
//        val today = Solar.fromDate(ExactDate.fromCal(calendar))
//        today.lunar?.also {
//            currentYear = it.year
//            currentMonth = it.month
//            currentDay = it.day
//        }
//
//        info.time = fixTime.time
//        info.sumTime = fixTime.sumTime
//        reBuild()
//        var currentIndex = 0
//
//        reBuild()
//    }
//
//
//    fun selectDaYun(pos: Int) {
//        if (pos == info!!.daYunIndex) {
//            return
//        }
//        info?.daYunIndex = pos
//        (vRcvDaYun.adapter as TextItemAdapter).getItem(pos)?.also {
//            info?.apply {
//                BaZhiHelper.setDyInfo(this, it.ganZhi)
//            }
//        }
//        var currentIndex = 0
//        (vRcvLiuNian.adapter as TextItemAdapter).setList((info?.getLiuNian(pos) ?: mutableListOf()).also {
//            it.onEachIndexed { index, iTextItem ->
//                (iTextItem as LiuNianItem).also { item ->
//                    if (item.year == currentYear) {
//                        currentIndex = index
//                        (vRcvLiuNian.adapter as TextItemAdapter).performClickItem(index)
//                    }
//                }
//            }
//        })
//        info?.liuNianIndex = -1
//        selectLiuNian(currentIndex)
//    }
//
//    private fun selectLiuNian(pos: Int) {
//        if (pos == info!!.liuNianIndex) {
//            return
//        }
//        info?.liuNianIndex = pos
//        var currentIndex = 0
//        (vRcvLiuYue.adapter as TextItemAdapter).setList(
//            (info?.getLiuYue() ?: mutableListOf()).also {
//                it.onEachIndexed { index, iTextItem ->
//                    (iTextItem as LiuYueItem).also { item ->
//                        LogUtils.d("selectLiuNian" + item.month + "," + currentMonth)
//                        if (item.year == currentYear && item.month == currentMonth) {
//                            currentIndex = index
//                            (vRcvLiuYue.adapter as TextItemAdapter).performClickItem(index)
//                        }
//                    }
//                }
//            })
//        (vRcvLiuNian.adapter as TextItemAdapter).getItem(pos)?.also {
//            info?.apply {
//                BaZhiHelper.setLnInfo(this, it.ganZhi)
//            }
//        }
//        info?.liuYueIndex = -1
//        selectLiuYue(currentIndex)
//    }
//
//    private fun selectLiuYue(pos: Int) {
//        if (pos == info!!.liuYueIndex) {
//            return
//        }
//        info?.liuYueIndex = pos
//        info?.liuRiIndex = -1
//        var currentIndex = 0
//        (vRcvLiuRi.adapter as TextItemAdapter).setList(
//            (info?.getLiuRi() ?: mutableListOf()).also {
//                it.onEachIndexed { index, iTextItem ->
//                    (iTextItem as LiuRIItem).also { item ->
//                        LogUtils.d("selectLiuYue:${currentMonth}-${currentDay},lunar:${item.lunarMonth}-${item.lunarDay}")
//                        if (item.lunarYear == currentYear && item.lunarMonth == currentMonth && item.lunarDay == currentDay) {
//                            currentIndex = index
//                            (vRcvLiuRi.adapter as TextItemAdapter).performClickItem(index)
//                        }
//                    }
//                }
//            }
//        )
//        (vRcvLiuYue.adapter as TextItemAdapter).getItem(pos)?.also {
//            info?.apply {
//                BaZhiHelper.setLyInfo(this, it.ganZhi)
//            }
//        }
//        selectLiuRi(currentIndex)
//    }
//
//    private fun reBuild() {
//        info?.also {
//            (vRcvResult.adapter as ResultAdapter).setList(it.buildList())
//            mTvExtra.text = it.buildBottom(false)
//        }
//    }
//
//    fun selectLiuRi(pos: Int) {
//        if (pos == info!!.liuRiIndex) {
//            return
//        }
//        info!!.liuRiIndex = pos
//        (vRcvLiuRi.adapter as TextItemAdapter).getItem(pos)?.also {
//            info?.apply {
//                BaZhiHelper.setLrInfo(this, it.ganZhi)
//            }
//        }
//    }
//
//    private fun chooseTime(time: Long) {
//        selectTime = time
//        startCs()
//    }
//
//    private fun initResultRcv() {
//        vRcvResult.layoutManager = GridLayoutManager(this, 9)
//        vRcvResult.adapter = ResultAdapter()
//    }
//
//
//    private fun initRcv() {
//        provinceRcv.layoutManager = LinearLayoutManager(this)
//        val provinceNames = DataUtils.getProvinceNames()
//        provinceRcv.adapter = ProvinceAdapter().apply {
//            setList(provinceNames)
//            setOnItemClickListener(object : BaseAdapter.OnItemClickListener<String> {
//                override fun onItemClick(data: String, position: Int) {
//                    onSelectProvince(data);
//                }
//            })
//        }
//        cityRcv.layoutManager = LinearLayoutManager(this)
//        cityRcv.adapter = CityAdapter().apply {
//            setOnItemClickListener(object : BaseAdapter.OnItemClickListener<City> {
//                override fun onItemClick(data: City, position: Int) {
//                    mSelectCity = data
//                    mTvCity.text = data.toString()
//                    cityContainer.visibility = View.GONE
//                }
//            })
//        }
//
//        onSelectProvince("广西")
//    }
//
//
//    fun onSelectProvince(province: String) {
//        mSelectProvince = province
//        val list = DataUtils.getCity(mSelectProvince)
//        var index = 0
//        if (province == "广西") {
//            index = list.indexOfFirst { it.city == "博白" }
//            mTvCity.text = list[index].toString()
//        }
//        mSelectCity = list[index]
//        (cityRcv.adapter as CityAdapter).setList(list)
//    }
//}
